



import bpy
from 全局控制.Node.节点和插座基类.bl_UpdateNode import *
import 全局控制.Node.节点和插座基类.bl_节点基类 as 基类
import 全局控制.Node.插座.bl_插座基类 as 插件基类




E_类型枚举 = [
	("TYPE_等于", "==", "", 0),
	("TYPE_不等于", "!=", "", 1),
	("TYPE_大于", ">", "", 2),
	("TYPE_小于", "<", "", 3),
	("TYPE_大于等于", ">=", "", 4),
	("TYPE_小于等于", "<=", "", 5),
]



class C_SN_关系运算(基类.C_SN_基类):
	bl_dname = 'bl_node_关系运算'
	bl_label = '关系运算'
	
	#m_物体name前缀 = bpy.props.StringProperty(name='前缀')
	m_运算类型 = bpy.props.EnumProperty(items=E_类型枚举, name="关系运算", default="TYPE_等于" )

	def init(self, context):
		super(C_SN_关系运算, self).f_init(context)
		self.inputs.new('C_NodeSocket_传递', name='A')
		self.inputs.new('C_NodeSocket_传递', name='B')
		self.outputs.new('C_NodeSocket_传递', name='C')
		
	def draw_buttons(self, context, layout):
		layout.prop(self, 'm_运算类型')
		
	def f_update(self, 是否向下传递=False, input插座=None):
		if self.m_运算类型 == 'TYPE_等于' :
			value = self.inputs[1].f_getData() == self.inputs[2].f_getData()
		elif self.m_运算类型 == 'TYPE_不等于' :
			value = self.inputs[1].f_getData() != self.inputs[2].f_getData()
		elif self.m_运算类型 == 'TYPE_大于' :
			value = self.inputs[1].f_getData() > self.inputs[2].f_getData()
		elif self.m_运算类型 == 'TYPE_小于' :
			value = self.inputs[1].f_getData() < self.inputs[2].f_getData()
		elif self.m_运算类型 == 'TYPE_大于等于' :
			value = self.inputs[1].f_getData() >= self.inputs[2].f_getData()
		elif self.m_运算类型 == 'TYPE_小于等于' :
			value = self.inputs[1].f_getData() <= self.inputs[2].f_getData()
		
		self.outputs['C'].f_setData(value)
		super(C_SN_关系运算, self).f_update(是否向下传递, input插座)
		


class C_NODE_AddMenu_关系运算(bpy.types.Operator):
	bl_idname = 'node.global_node_relation_operation'
	bl_label = '关系运算节点'
	bl_options = {'REGISTER', 'UNDO'}
	
	def execute(operator, context):
		operator.use_transform = True
		bpy.ops.node.add_node(type='C_SN_关系运算', use_transform=True)
		return {'FINISHED'}



classes = (
	C_SN_关系运算,
	C_NODE_AddMenu_关系运算,
	
)


def register():
	for c in classes:
		bpy.utils.register_class(c)
		

def unregister():
	for c in classes:
		bpy.utils.unregister_class(c)

	

